import { useCinfSysCode } from '@src/components/useComponent';
import { Form, Row, Col, Input, Select, Button, Space, Modal } from 'antd';
import qs from 'qs';
import { useEffect, useState } from 'react';
import { useHistory } from 'react-router-dom';
interface ServicerNamesProps {
  code: string;
  name: string;
}
export const ProductConfigurationSearchForm = ({ searchBtnF }: any) => {
  let history = useHistory();
  const [form] = Form.useForm();
  const [addPlanyForm] = Form.useForm();
  const { Option } = Select;
  const { confSysCode } = useCinfSysCode();
  const [resetButtonDisabled, setResetButtonDisabled] = useState<boolean>(true);
  const onReset = () => {
    form.resetFields();
    setResetButtonDisabled(true);
  };
  const onFinish = async (values: any) => {
    searchBtnF(values);
  };
  const onValuesChange = () => {
    setResetButtonDisabled(!qs.stringify(form.getFieldsValue()));
  };
  const onOk = () => {
    addPlanyForm.validateFields().then((values: any) => {
      console.log(values);
    });
  };
  return (
    <>
      <Form
        className="anTopSearchForm fff pad20"
        form={form}
        layout="inline"
        name="maitainSearcher"
        onFinish={onFinish}
        onValuesChange={onValuesChange}
      >
        <Form.Item label="产品类型" name="productItemType" rules={[{ required: true }]}>
          <Select showSearch allowClear optionFilterProp="children" placeholder="请选择">
            {confSysCode?.map((item: any, index: number) => {
              return (
                <Option key={item.code} value={item.code}>
                  {item.codeName}
                </Option>
              );
            })}
          </Select>
        </Form.Item>
        <div className="searchBtnBox">
          <div>
            <Button
              onClick={() => {
                history.push('/productConfigurationAdd');
              }}
            >
              增加产品配置
            </Button>
            <Button className="marg020" disabled={resetButtonDisabled} onClick={onReset}>
              重置
            </Button>
            <Button type={'primary'} htmlType="submit">
              搜索
            </Button>
          </div>
        </div>
      </Form>
    </>
  );
};
